package com.sq.goodline.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.sq.goodline.annotation.IgnoreAccessToken;
import com.sq.goodline.controller.dto.AxbRequestDto;
import com.sq.goodline.controller.dto.AxbResultDto;
import com.sq.goodline.controller.dto.DeleteAxbDto;
import com.sq.goodline.controller.dto.PartnerTokenResultDto;
import com.sq.goodline.controller.dto.TransResponse;
import com.sq.goodline.service.AuthService;
import com.sq.goodline.service.AxbService;
import com.sq.goodline.util.Constants;

@RestController
@RequestMapping("/openapi")
public class OpenApiController {
     
	@Autowired
	AxbService axbService;
	@Autowired
	AuthService authService ;
	
	
    @GetMapping(value = "/genAccessToken")
//    @IgnoreAccessToken
    public TransResponse<PartnerTokenResultDto> genAccessToken(@RequestParam(value = "partnerCode",required=true) String partnerCode,
    											    @RequestParam(value = "partnerSecret",required=true) String partnerSecret) {
    	 
    	return authService.genAccessToken(partnerCode, partnerSecret);

    }
    
    @PostMapping(value = "/axbInsert")
	public TransResponse<List<AxbResultDto>> axbInsert(@RequestHeader("TraceId") String traceId,
			@RequestHeader(Constants.ACCESS_TOKEN) String token,
			@RequestBody List<AxbRequestDto> axbRequest) {
    	return axbService.axbInsert(axbRequest);
	}
    
    /**
     * 暂不开放，axb绑定支持覆盖
     * @param traceId
     * @param token
     * @param deleteAxbRequest
     * @return
     */
    @PostMapping(value = "/axbDelete")
	public TransResponse<DeleteAxbDto> axbDelete(@RequestHeader("TraceId") String traceId,
			@RequestHeader(Constants.ACCESS_TOKEN) String token,
			@RequestBody List<DeleteAxbDto> deleteAxbRequest) {
    	return null;
	}
    
}